home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 79 / maccd 79.iso / multimedial / GL Tron / Source / gltron / tools / font-tex.pl < prev   
Encoding:
Perl Script  |  2001-05-13  |  2.1 KB  |  109 lines  |  [TEXT/CWIE]

  1. #!/usr/bin/perl -w
  2.  
  3. use Gimp;
  4. # use X11::Protocol;
  5.  
  6. exit Gimp::main();
  7.  
  8. sub net {
  9.  
  10.   set_trace(TRACE_ALL);
  11. #  $x = X11::Protocol->new();
  12.  
  13.   $author = "Andreas Umbach";
  14.   $copyright = "Andreas Umbach (c)";
  15.   $date = localtime;
  16.  
  17.   $font = "-ttf-xenotron-medium-*-*-regular-*-*-*-*-*-*-*-*";
  18.   $name = "xenotron";
  19.   $lower = 32;
  20.   $upper = 126;
  21.  
  22.   $tw = 256;
  23.   $w = 32;
  24.  
  25.   $border = 1;
  26.   $h = $w - 2 * $border;
  27.  
  28. ## 
  29. ##   $fid = $x->new_rsrc;
  30. ##   $x -> req('OpenFont', $fid, $font);
  31. ##   print "font: $fid\n";
  32. ##   %fontinfo = $x->req('QueryFont', $fid);
  33. ## 
  34. ##   $chars = $fontinfo{"char_infos"};
  35. ##   print "char width:\n";
  36. ##   foreach $char (@$chars) {
  37. ##     print $$char[3], "\n";
  38. ##   }
  39. ##   exit(1);
  40. ## 
  41.   $imgcount = 0;
  42.  
  43.   &createImage;
  44.  
  45.   $x = 0; $y = 0;
  46.   for($i = 0; $i <= $upper - $lower; $i++) {
  47.     $x += $w;
  48.     if($x + $w > $tw) {
  49.       $x = 0;
  50.       $y += $w;
  51.       if($y + $w > $tw) {
  52.     # create second texture
  53.     print("font does not fit in - creating second image\n");
  54.     push @drws, $drw;
  55.     &createImage;
  56.  
  57.     $imgcount++;
  58.     $y = 0;
  59.       }
  60.     }
  61.  
  62.     print "($x, $y): '" . chr($i + $lower) . "'\n";
  63.     next if($i + $lower == 32);
  64.     # get text extents to center char...
  65.     ($width,$height,$ascent,$descent) =
  66.       gimp_text_get_extents_fontname(chr($i + $lower), $h, 1, $font);
  67.     $px = $x + ($w - $width) / 2;
  68.     $py = $y + ($w - $height) / 2;
  69.  
  70.     $text_layer = gimp_text_fontname($drw, $px, $py, chr($i + $lower),
  71.                      $border, 1, $h, 1, $font);
  72.     gimp_floating_sel_anchor($text_layer);
  73.   }
  74.  
  75.   push @drws, $drw;
  76.   for($i = 0; $i <= $imgcount; $i++) {
  77.     $drw = $drws[$i];
  78.     $fname = "/tmp/" . $name . ".$i" . ".sgi";
  79.     file_sgi_save($drw, $fname, $fname, 0);
  80.   }
  81. }
  82.  
  83. sub createImage {
  84.   $img = gimp_image_new($tw, $tw, RGB);
  85.   $drw = gimp_layer_new($img, $img->width, $img->height ,RGB, "BG", 100,
  86.             NORMAL_MODE);
  87.   $drw->add_alpha();
  88.   $drw->add_layer(-1); # -1 means at top of stack
  89.  
  90.   gimp_palette_set_background("black");
  91.   gimp_edit_fill($drw);
  92.   $img->selection_all();
  93.   $drw->edit_clear();
  94.  
  95.   gimp_palette_set_foreground([255, 255, 255]); # "white"
  96. }
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.